package com.hoshiibuy.fileServer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hoshiibuy.fileServer.model.CreateBucketRequest;
import com.hoshiibuy.fileServer.result.Result;
import com.hoshiibuy.fileServer.service.BucketService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/bucket")
@Api(tags = "存储空间操作接口")
public class BucketController {
	@Autowired
	private BucketService bucketService;

	@RequestMapping(value = "/create", method = RequestMethod.POST)
	@ApiOperation(value = "创建一个存储空间", notes = "已存在无法创建", consumes = "application/json")
	public Result createBucket(CreateBucketRequest param) throws Exception {
		if (bucketService.createBucket(param)) {
			return Result.wrapSuccess("操作成功");
		} else {
			return Result.wrap500Error("操作失败,存储空间已存在");
		}

		// return "test";
	}

	@RequestMapping(value = "/test", method = { RequestMethod.POST, RequestMethod.GET })
	@ApiIgnore
	public String test() throws Exception {
		bucketService.test();
		return "test";
	}
}
